<!DOCTYPE HTML>
<html>
<head>
    <title>编辑团购活动</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<div id="form1" style="padding-left: 60px">

    <span style="width:60px;display:inline-block;">团购价格：</span>
    <input id="groupPrice" name="groupPrice" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.price%>"/>

    <span style="width:60px;display:inline-block;">团购积分：</span>
    <input id="groupScore" name="groupScore" class="mini-textbox" required="true"  type="number" style="width:155px;" value="<%= result.groupScore%>"/>
    <br/><br/>
    <span style="width:60px;display:inline-block;">成团人数：</span>
    <input id="groupPeopleNum" name="groupPeopleNum" class="mini-textbox" required="true" type="number"  style="width:155px;" value="<%= result.groupPeopleNum%>"/>
    <br/><br/>
    <span style="width:90px;display:inline-block;">最小成团人数：</span>
    <input id="minGroupPeopleNum" name="minGroupPeopleNum" class="mini-textbox" required="true" type="number"  style="width:155px;" value="<%= result.minGroupPeopleNum%>"/>
    <br/><br/>
    <span style="width:90px;display:inline-block;">每人限购数量：</span>
    <input id="limitNum" name="limitNum" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.limitNum%>"/>
    <br/><br/>
    <span style="width:100px;display:inline-block;">拼团时长(小时)：</span>
    <input id="groupDuration" name="groupDuration" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.groupDuration%>"/>
    <br/><br/>
    <span style="width:90px;display:inline-block;">活动开始时间：</span>
    <input id="groupStartTime" class="mini-datepicker" style="width:200px;"
           format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true" showClearButton="false" required="true" value="<%= result.groupStartTime%>"/>
    <br/><br />

    <span style="width:90px;display:inline-block;">活动结束时间：</span>
    <input id="groupEndTime" class="mini-datepicker" style="width:200px;" onvaluechanged="onValueChanged"
           format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true" showClearButton="false" required="true" value="<%= result.groupEndTime%>"/>
    <br/><br />

</div>
<div style="margin: 30px 0;text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="editGroup()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
</div>
</body>
<script>
    var objectId = '<%=result.objectId%>';
    function editGroup(){
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            alert("请正确填写数据")
            return
        };
        var data = {}

        data.objectId = objectId;
        data.groupPrice = mini.get("groupPrice").getValue();
        data.groupScore = mini.get("groupScore").getValue();
        data.groupPeopleNum = mini.get("groupPeopleNum").getValue();
        data.minGroupPeopleNum = mini.get("minGroupPeopleNum").getValue();
        data.limitNum = mini.get("limitNum").getValue();
        data.groupDuration = mini.get("groupDuration").getValue();
        data.groupStartTime = mini.get("groupStartTime").getValue();
        data.groupEndTime = mini.get("groupEndTime").getValue();

        if(data.groupPeopleNum<2){
            alert("成团人数不能小于2人")
            return
        }
        if(data.minGroupPeopleNum<2){
            alert("最小成团人数不能小于2人")
            return
        }

        if(data.limitNum<=0){
            alert("每人限购数量不能等于0")
            return
        }
        if(data.groupDuration<=0){
            alert("拼团时长不能小于1小时")
            return
        }
        let groupStartTime = Date.parse(mini.get("groupStartTime").getValue());
        let groupEndTime = Date.parse(mini.get("groupEndTime").getValue());

        // var currentTime = (new Date()).getTime();
        // if(groupStartTime<currentTime){
        //     alert("活动开始时间必须大于当前时间")
        //     return
        // }

        if (groupStartTime==""||groupEndTime<=groupStartTime){
            alert("请先输入活动开始时间，活动结束时间必须大于开始时间")
            return
        }
        $.ajax({
            type: "POST",
            url: "/getdata/editGroupActivityData",
            data:data,
            success: function (result) {
                if(result =="1"){
                    alert("保存成功");
                    CloseWindow("save");
                }else{
                    alert("保存失敗")
                    CloseWindow("save");
                }
            }
        })
    }

    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function onCancel(e) {
        CloseWindow("cancel");
    }


    function onValueChanged() {
        var groupStartTime = Date.parse(mini.get("groupStartTime").getValue());
        var groupEndTime = Date.parse(mini.get("groupEndTime").getValue());
        var end = mini.get("groupEndTime");
        if (groupStartTime=""||groupEndTime<=groupStartTime){
            alert("请先输入活动开始时间，活动结束时间必须大于开始时间")
            end.setValue('');
        }
    }

</script>
</html>